main_df <- main_df %>% mutate(group.treatment = factor(group.treatment, levels = c("random", "merit", "patronage")))

any_vign_bivariate <-lm(any_vign ~ factor(group.treatment), weights = weights, main_df %>% filter(pub_official_indicator == 1))
all_vign_bivariate <- lm(all_vign ~ factor(group.treatment), weights = weights,main_df %>% filter(pub_official_indicator == 1))
avg_vign_bivariate <- lm(avg_vign ~ factor(group.treatment), weights = weights, main_df %>% filter(pub_official_indicator == 1))

any_vign_covariate <-lm(any_vign ~ factor(group.treatment) + player.age + factor(player.education == 4),weights = weights, main_df %>% filter(pub_official_indicator == 1))
all_vign_covariate <- lm(all_vign ~ factor(group.treatment) + player.age + factor(player.education == 4),weights = weights, main_df %>% filter(pub_official_indicator == 1))
avg_vign_covariate <- lm(avg_vign ~ factor(group.treatment) + player.age + factor(player.education == 4), weights = weights,main_df %>% filter(pub_official_indicator == 1))

observations <- c(nobs(any_vign_bivariate),nobs(all_vign_bivariate),nobs(avg_vign_bivariate),nobs(any_vign_covariate),nobs(all_vign_covariate),nobs(avg_vign_covariate))

any_vign_bivariate <- coeftest(any_vign_bivariate, vcov=vcovHC(any_vign_bivariate,type="HC0"), cluster = ~cluster)
all_vign_bivariate <- coeftest(all_vign_bivariate, vcov=vcovHC(all_vign_bivariate,type="HC0"), cluster = ~cluster)
avg_vign_bivariate <- coeftest(avg_vign_bivariate, vcov=vcovHC(avg_vign_bivariate,type="HC0"), cluster = ~cluster)
any_vign_covariate <- coeftest(any_vign_covariate, vcov=vcovHC(any_vign_covariate,type="HC0"), cluster = ~cluster)
all_vign_covariate <- coeftest(all_vign_covariate, vcov=vcovHC(all_vign_covariate,type="HC0"), cluster = ~cluster)
avg_vign_covariate <- coeftest(avg_vign_covariate, vcov=vcovHC(avg_vign_covariate,type="HC0"), cluster = ~cluster)

table <- list(any_vign_bivariate, all_vign_bivariate, avg_vign_bivariate, any_vign_covariate, all_vign_covariate, avg_vign_covariate)

note_text <- paste("Beta coefficients from OLS regression using survey weights. Standard errors were calculated using the Huber-White (HC0) correction and clustered at the group-session level. 
                   The outcomes measures are indices capturing whether public official offered Weberian responses to (1) any of the vignettes; 
                   (2) all of the vignettes; and (3) an average indexed measure of responses.")

table = stargazer(table, type = 'latex', 
                  title = "The Effect of Selection Mode on Bureaucratic Neutrality",
                  label = 'tab:weber_weight',
                  model.names = F,
                  model.numbers = T,
                  digits = 3,
                  column.separate = c(1,1 , 1, 1, 1, 1),
                  column.labels = c("Any", "All", "Avg", "Any", "All", "Avg"),
                  dep.var.labels = NULL, 
                  add.lines = list(c("Covariates", "N", "N", "N", "Y", "Y", "Y"),
                                   c("Observations", observations)),
                  #omit = c("player.age", "player.education"),
                  covariate.labels = c("Treatment: Merit", "Treatment: Patronage", "Age", "Education: College", "Constant"),
                  
                  #star.cutoffs = c(0.05, 0.01),
                  #float.env = 'sidewaystable',
                  keep.stat = c("n"),
                  notes = NULL,
                  notes.align = 'l')

write_latex(table[-c(10, 11, 12, 18, 21, 24, 27, 30, 36)], note_text, './outputs/tables/table_a6.tex', .8)


